/*tree on the level
 *first : building the tree
 *second : BFS
 * */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int maxn =  256;
int cnt = 0;
bool failed = false;
char s[maxn];

struct Node{
	bool have_value;
	int v;
	Node *left, *right;
	Node():have_value(false), left(NULL), right(NULL){}
};

Node* root;
queue<Node*> freenodes;
Node node[maxn];

void init()
{
	for(int i = 0; i < maxn;i++)
		freenodes.push(&node[i]);
}

Node* newnode() 
{
	Node* u = freenodes.front();
	u->left = u->right = NULL;
	u->have_value = false;
	freenodes.pop();
	return u;
}
void deletenode(Node* u){ freenodes.push(u);}


bool read_input();
bool bfs(vector<int>& ans);
void addnode(int vv,char* s);

int main()
{
	init();

	read_input();
	vector<int> ans;
	bfs(ans);
	for(auto it = ans.begin(); it != ans.end(); ++it){
		printf("%d, ",*it);
	}
	return 0;
}

bool read_input()
{
	failed = false;
	root = newnode();
	for(;;){
		if(scanf("%s",s) != 1) return false;
		if(!strcmp(s,"()")) break;//end flag
		int v;
		sscanf(&s[1],"%d",&v);//get node value, "11,LL)"->11,can cult off
		addnode(v,strchr(s,',')+1);//the pointer of location
	}
	return true;
}

void addnode(int v,char *s)// pointer to LL)
{
	int n = strlen(s);
	Node* u = root;
	for(int i = 0;i < n; i++){
		if(s[i] == 'L'){
			if(u->left == NULL) u->left = newnode();
			u = u->left;
		} else if(s[i] == 'R'){
			if(u->right == NULL) u->right = newnode();
			u = u->right;
		}
	}
	if(u->have_value) failed = true;
	u->v = v;
	u->have_value = true;
}

bool bfs(vector<int>& ans)
{
	queue<Node*> q;//因为每一行的节点数量不一定，使用队列会比较方便。
	ans.clear();
	
	q.push(root);
	while(!q.empty()){
		Node *u = q.front();
		q.pop();
		if(!u->have_value) return false;
		ans.push_back(u->v);
		if(u->left != NULL) q.push(u->left);
		if(u->right != NULL) q.push(u->right);
	}

	return true;
}

#if 0
const int root = 1;
int cnt = 0;
int Left[maxn], Right[maxn],v[maxn];
bool have_value[maxn], failed = false;
char s[maxn];

void newtree() {Left[root] = Right[root] = 0; have_value[root] = false;cnt = root;}
int newnode() { int u = ++cnt; Left[u] = Right[u] = 0; have_value[u] = false; return u;}

bool read_input();
bool bfs(vector<int>& ans);
void addnode(int vv,char* s);

int main()
{
	read_input();

	vector<int> ans;
	bfs(ans);

	for(auto it = ans.begin(); it != ans.end(); ++it){
		printf("%d, ",*it);
	}

	return 0;
}

bool read_input(void)
{
	failed = false;
	newtree();
	for(;;){
		if(scanf("%s",s) != 1) return false;
		if(!strcmp(s,"()")) break;
		int v;
		sscanf(&s[1],"%d",&v);
		addnode(v,strchr(s,',')+1);
	}
	return true;
}

void addnode(int vv,char* s)
{
	int n = strlen(s);
	int u = root;
	for(int i = 0; i < n;i++){
		if(s[i] == 'L'){
			if(Left[u] == 0)	Left[u] = newnode();
			u = Left[u];
		} else if(s[i] == 'R'){
			if(Right[u] == 0)	Right[u] = newnode();
			u = Right[u];
		}
	}
	if(have_value[u])	failed = true;
	v[u] = vv;
	have_value[u] = true;
}

bool bfs(vector<int>& ans){
	queue<int> q;
	ans.clear();
	q.push(root);
	while(!q.empty()){
		int u = q.front(); q.pop();
		if(!have_value[u]) return false;
		ans.push_back(v[u]);
		if(Left[u] != 0) q.push(Left[u]);
		if(Right[u] != 0) q.push(Right[u]);
	}
	return true;
}
#endif

#if 0
const int maxn = 1024;
char s[maxn];
bool failed;

struct Node{
	bool have_value;
	int v;
	Node *left, *right;
	Node():have_value(false), left(NULL), right(NULL){}
};

Node* root;
Node* newnode() {return new Node();}

void addnode(int v, char *s);
bool read_input();
bool bfs(vector<int>& ans);
void print_tree(Node *u);
void remove_tree(Node *u);

int main1()
{
	/*build the tree from input*/
	read_input();

	print_tree(root);

	vector<int> ans;
	bfs(ans);

	for(auto it = ans.begin(); it != ans.end(); ++it){
		printf("%d, ",*it);
	}
	remove_tree(root);
	return 0;
}

bool read_input()
{
	failed = false;
	root = newnode();
	for(;;){
		if(scanf("%s",s) != 1) return false;
		if(!strcmp(s,"()")) break;//end flag
		int v;
		sscanf(&s[1],"%d",&v);//get node value, "11,LL)"->11,can cult off
		addnode(v,strchr(s,',')+1);//the pointer of location
	}
	return true;
}

void addnode(int v,char *s)// pointer to LL)
{
	int n = strlen(s);
	Node* u = root;
	for(int i = 0;i < n; i++){
		if(s[i] == 'L'){
			if(u->left == NULL) u->left = newnode();
			u = u->left;
		} else if(s[i] == 'R'){
			if(u->right == NULL) u->right = newnode();
			u = u->right;
		}
	}
	if(u->have_value) failed = true;
	u->v = v;
	u->have_value = true;
}

bool bfs(vector<int>& ans)
{
	queue<Node*> q;//因为每一行的节点数量不一定，使用队列会比较方便。
	ans.clear();
	
	q.push(root);
	while(!q.empty()){
		Node *u = q.front();
		q.pop();
		if(!u->have_value) return false;
		ans.push_back(u->v);
		if(u->left != NULL) q.push(u->left);
		if(u->right != NULL) q.push(u->right);
	}

	return true;
}

void print_tree(Node *u)
{
	if(u == NULL ) return;
	print_tree(u->left);
	print_tree(u->right);
	if(u->have_value)	printf("%d, ",u->v);
}
void remove_tree(Node *u)
{
	if(u == NULL) return;
	remove_tree(u->left);
	remove_tree(u->right);
	delete u;
}
#endif
